
#include "CGameApplication.h"
#include "Player.h"

void Player::movePlayer(int keyPressed)
{
	switch(keyPressed)
	{
	case SDLK_UP:
		{
			lastMakeMovement = SDLK_UP;
			if ( ! CGameApplication::getInstance()->getCMapManager()->checkCollisionWithMap( CGameApplication::getInstance()->getGameApp()->getCurrentMap(), spritePlayer, SDLK_UP) )
			{
				spritePlayer->setPosY(  spritePlayer->getPosY() - spritePlayer->getSpeedY()	);
				spritePlayer->setOffsetY(  spritePlayer->getOffsetY() - spritePlayer->getSpeedY() );	
			}
			break;
		}
	
	case SDLK_DOWN:
		{
			lastMakeMovement = SDLK_DOWN;
			if ( ! CGameApplication::getInstance()->getCMapManager()->checkCollisionWithMap( CGameApplication::getInstance()->getGameApp()->getCurrentMap(), spritePlayer, SDLK_DOWN) )
			{
				spritePlayer->setPosY(  spritePlayer->getPosY() + spritePlayer->getSpeedY()	);
				spritePlayer->setOffsetY(  spritePlayer->getOffsetY() + spritePlayer->getSpeedY() );
			}
			break;
		}

	case SDLK_LEFT:
		{
			lastMakeMovement = SDLK_LEFT;
			if ( ! CGameApplication::getInstance()->getCMapManager()->checkCollisionWithMap( CGameApplication::getInstance()->getGameApp()->getCurrentMap(), spritePlayer, SDLK_LEFT) )
			{
				spritePlayer->setPosX(  spritePlayer->getPosX() - spritePlayer->getSpeedX()	);
				spritePlayer->setOffsetX(  spritePlayer->getOffsetX() - spritePlayer->getSpeedX() );	
			}
			break;
		}

	case SDLK_RIGHT:
		{
			lastMakeMovement = SDLK_RIGHT;
			if ( ! CGameApplication::getInstance()->getCMapManager()->checkCollisionWithMap( CGameApplication::getInstance()->getGameApp()->getCurrentMap(), spritePlayer, SDLK_RIGHT) )
			{
				spritePlayer->setPosX(  spritePlayer->getPosX() + spritePlayer->getSpeedX()	);
				spritePlayer->setOffsetX(  spritePlayer->getOffsetX() + spritePlayer->getSpeedX() );
			}
			break;
		}
	}
}